/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/KeyExchange/dhCalcThread.cpp,v 1.4 2003/11/21 12:39:24 itsme Exp $
 *
 *
 *  this thread processes diffiehellman calculation requests
 *
 *  each calculation request reports its result back to the main DH-thread
 *  by setting either the 'success'-event, or the 'failure'-event.
 *
 */

#include "dhCalcThread.h"

DWORD CalcThread::ThreadProc()
{
    CalcRequest *m;
    debug("DH-calc thread started\n");
    while (m_calcrequests.GetWait(m)) {
        debug("DH-processing calc request\n");
        
        DWORD t0= GetTickCount();
        bool bRes= m->doCalculation();
        DWORD t1= GetTickCount();

        debug("DH-calc result in %d msec\n", t1-t0);

        if (bRes)
            SetEvent(m->m_hSuccessEvent);
        else
            SetEvent(m->m_hFailEvent);

        delete m;
    }

    return 0;
}

void CalcThread::SetHighPriority()
{
    SetThreadPriority(Handle(), THREAD_PRIORITY_ABOVE_NORMAL);
}

void CalcThread::SetLowPriority()
{
    SetThreadPriority(Handle(), THREAD_PRIORITY_BELOW_NORMAL);
}

